<style>
.rate {color: #fa6}
#scoreTable , #statistics-table{background: #ccc; margin:5px;}
#scoreTable th ,#statistics-table th{background: #feb}
#scoreTable th  , #scoreTable td  {width:42px;padding:1px}
#statistics-table caption {font-weight: bold; font-size: 14px}
#statistics-table th ,#statistics-table td {width:60px; margin:1px;padding: 2px; text-align:center}
#scoreTable tr , #statistics-table tr {padding:1px}
.score {text-align:right;}
.failed {color: red}

</style>
<script>
function checkFail()
{
    $.each($(".score"),function(){
        var s = $(this).text();
        if (s !='' && s < 60)
              $(this).addClass('failed');
     });
}



$(function(){
	checkFail();
	$("#scoreDataList table tbody tr:even").addClass('even');
    $("#scoreDataList table tbody tr:odd").addClass('odd');

});
</script>
<?php $flag=false;?>
<div id="scoreDataList">
<table id="scoreTable">
<thead>
<tr>
<th rowspan="2"><?php echo $this->translate('number')?></th>
<th rowspan="2"><?php echo $this->translate('student name')?></th>
<?php foreach($this->subject as $scopeName=>$val):?>
<?php if (count($val) >1):?>
<?php $flag = true;?>
<th colspan="<?php echo count($val)?>"><?php echo $scopeName?></th>
<?php else:?>
<th rowspan="2"><?php echo $val[0]['name']?>
<?php if ($this->rateCount):?><br/><span class="rate">(<?php echo $val[0]['rate']?>)</span><?php endif?>
</th>
<?php endif;?>
<?php endforeach?>
<th rowspan="2"><?php echo $this->translate('Total score')?></th>
<th rowspan="2"><?php echo $this->translate('Average score')?></th>
<th rowspan="2"><?php echo $this->translate('Rank')?></th>
</tr>
<?php if ($flag):?>
<tr>
<?php foreach($this->subject as $val):?>
<?php if (count($val) > 1):?>
<?php foreach($val as $row):?>
<th><?php echo $row['name']?>
<?php if ($this->rateCount):?><br/><span class="rate">(<?php echo $row['rate']?>)</span><?php endif?>
</th>
<?php endforeach?>
<?php endif?>
<?php endforeach?>
</tr>
<?php endif?>
</thead>
<tbody>
<?php foreach ($this->studentScore['score'] as $val):?>
<tr>
<td><?php echo $val['number']?></td>
<td><?php echo $val['name']?></td>
<?php foreach($this->subject as $subjectArr):?>
<?php foreach($subjectArr as $row):?>
<td class="score"><?php if(isset($val['score'][$row['subject_sn']]))echo $val['score'][$row['subject_sn']]?></td>
<?php endforeach?>
<?php endforeach?>
<td class="score"><?php echo $val['total']?></td>
<td class="score"><?php echo $val['average']?></td>
<td  style="text-align:right;padding:2px"><?php echo $val['sort']?></td>
</tr>
<?php endforeach?>
<tr>
<td colspan="2" style="text-align:center"><?php echo $this->translate('Average score')?></td>
<?php foreach($this->subject as $subjectArr):?>
<?php foreach($subjectArr as $row):?>
<td class="score"><?php if (isset($this->studentScore['subjectAverage'][$row['subject_sn']]))echo $this->studentScore['subjectAverage'][$row['subject_sn']]?></td>
<?php endforeach?>
<?php endforeach?>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><?php echo $this->translate('Standard deviation')?></td>
<?php foreach($this->subject as $subjectArr):?>
<?php foreach($subjectArr as $row):?>
<td style="text-align:right;padding:2px">
<?php if (isset($this->studentScore['subjectStd'][$row['subject_sn']]))echo $this->studentScore['subjectStd'][$row['subject_sn']]?></td>
<?php endforeach?>
<?php endforeach?>
<td colspan="3"></td>
</tr>
</tbody>
</table>
<hr/>
<table id="statistics-table">
<caption><?php echo $this->translate('Results distribution')?></caption>
<thead>
<tr>
<th> <?php echo $this->translate('score') ?> <br/>/<br/> <?php echo $this->translate('subject')?></th>
<?php foreach($this->subject as $subjectArr):?>
<?php foreach($subjectArr as $row):?>
<th><?php echo $row['name']?></th>
<?php endforeach?>
<?php endforeach?>
</tr>
</thead>
<tbody>
<?php foreach($this->studentScore['statistics'] as $id=>$val):?>
<tr>
<td><?php echo $id?></td>
<?php foreach($this->subject as $subjectArr):?>
<?php foreach($subjectArr as $row):?>
<td><?php if(isset($val[$row['subject_sn']]) and $val[$row['subject_sn']]>0) echo$val[$row['subject_sn']]?></td>
<?php endforeach?>
<?php endforeach?>
</tr>
<?php endforeach?>
</tbody>
</table>
</div>